<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button id="btn">hello</button>
    <div id="box1">hello</div>
    <div id="box2">jack</div>
    <div id="box3">lili</div>
    <div id="box4">20</div>

    <script>
      /*
      发布订阅模式（编程模式）
      */
      const btn = document.getElementById("btn");
      box1.addEventListener("update", function () {
        this.innerHTML += "!";
      });
      btn.onclick = function () {
        box1.dispatchEvent(new Event("update"));
      };
    </script>
  </body>
</html>
